package com.boot.ys.mybatisplus.controller;

import com.boot.ys.mybatisplus.entity.Abc;
import com.boot.ys.mybatisplus.result.Result;
import com.boot.ys.mybatisplus.service.OSSFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/oss")
@Api(tags = "OSS测试接口")
public class OSSFileController {

    @Autowired
    private OSSFileService ossFileService;


    /**
     * 上传图片，只上传图片
     * 接收请求
     * 返回响应
     */
    @ApiOperation("测试OSS")
    @PostMapping("/picfile")
    public Result ossUpload(@RequestParam(value = "file") MultipartFile file){
        String url = ossFileService.ossUpload(file);
        return Result.ok(url);
    }


    /**
     * 上传到阿里云Oss上面可以上传其他文件
     * @param
     * @return
     */
    @PostMapping("/uploadAll")
    @ApiOperation("测试")
    public Result uploadAll(@RequestParam(value = "file") MultipartFile file){
        String url = ossFileService.uploadAll(file);
        return Result.ok(url);
    }

    /**
     * 删除阿里云Oss上面的文件
     *要删除的文件地址我写死了的
     */
    @PostMapping("deleteOssFile")
    public Result deleteOssFile(){
        ossFileService.deleteOssFile();
        return Result.ok();
    }







}
